package com.example.alertdialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TableLayout;

public class MainActivity extends Activity {

	private EditText et;
	private String[] fuck = new String[] { "������������", "ɫ�鲻������", "���ɧ����Ϣ", "���?��,����������", "������Ϣ����汾�������Ϣ" };
	private boolean[] b = new boolean[] { true, false, true, false, false };
	private String result = "";
	private String[] fuck1 = new String[] { "������������", "ɫ�鲻������", "���ɧ����Ϣ", "���?��,����������", "������Ϣ����汾�������Ϣ" };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		et = (EditText) findViewById(R.id.show);
		System.out.println("123");
		System.out.println("123");

	}

	// ����򵥶Ի���ķ���
	public void simple(View v) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setTitle("�򵥶Ի���");
		builder.setMessage("����һ���򵥵ĶԻ���");
		// builder.setPositiveButton()���������2�������һ��ΪButton��ʾ�����֣��ڶ�������Ϊ�գ�Ҳ�������ü����¼�
		builder.setPositiveButton("ȷ��", new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				et.setText("������ȷ����ť��");
			}
		});
		
		builder.setNegativeButton("ȡ��", new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				et.setText("������ȡ��ť��");
			}
		}).create().show();

	}

	// ������ĵ���б�Ի���ķ���
	public void list(View v) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setTitle("�б�Ի���");
		// builder.setItems()���������2�������һ��ΪҪ��ʾ�����飬�ڶ�������Ϊ�գ�Ҳ�������ü����¼�
		builder.setItems(fuck, new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				et.setText("��ѡ�����:" + fuck[which] + "��");

			}
		});
		// ���û�ж�"ȷ��"��"ȡ��"��ť���ü����¼�.
		builder.setPositiveButton("ȷ��", null);
		builder.setNegativeButton("ȡ��", null).create().show();
	}

	// ��ѡ�б�ĶԻ���ķ���
	public void singleChoice(View v) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setTitle("��ѡ�б�ĶԻ���");
		// ��������һ��Ϊ���飬�ڶ���ΪĬ��ѡ�е��б�����������Ϊ��Ҳ����Ϊ�����¼�
		builder.setSingleChoiceItems(fuck, 1, new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				et.setText("��ѡ����ǣ�" + fuck[which] + "��");

			}
		});
		// ���һ��Ҳû�ж�"ȷ��"��"ȡ��"��ť���ü����¼�.
		builder.setPositiveButton("ȷ��", null);
		builder.setNegativeButton("ȡ��", null).create().show();

	}

	// ��ѡ�б�ĶԻ���ķ���
	public void multiChoice(View v) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setTitle("��ѡ�б�ĶԻ���");
		// ��������һ��Ϊ���飬�ڶ���Ϊ�������͵�Ҳ��Ĭ��ѡ������������Ϊ��Ҳ����Ϊ�����¼�
		builder.setMultiChoiceItems(fuck, b, new OnMultiChoiceClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which,
					boolean isChecked) {

			}
		});
		builder.setPositiveButton("ȷ��", new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				for (int i = 0; i < b.length; i++) {
					if (b[i]) {
						result += fuck[i] + ",";
					}
				}
				et.setText("��ѡ����У�" + result + "��");

			}
		});
		builder.setNegativeButton("ȡ��", null).create().show();

	}

	// �Զ���Ի���ķ���
	public void style(View v) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setTitle("�Զ���ĶԻ���");
		// ���������һ��Ϊ���������ڶ�����Ϊ��Ҳ�����ü����¼���������������������������ģ����֣�����
		builder.setAdapter(new ArrayAdapter<String>(this, R.layout.sad, fuck),
				new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						et.setText("��ѡ���Ӣ���ǣ�" + fuck[which] + "��");

					}
				});
		builder.setPositiveButton("ȷ��", null);
		builder.setNegativeButton("ȡ��", null).create().show();

	}

	// ��һ���Զ���Ի���ķ���
	public void coolstyle(View v) {

		// ��̬���ز��ֵķ�ʽ�ڳ������е�ʱ���ȡ�������ļ�
		TableLayout login = (TableLayout) getLayoutInflater().inflate(
				R.layout.login, null);
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setTitle("�Զ���ĶԻ���");
		builder.setView(login);
		builder.setPositiveButton("ȷ��", null);
		builder.setNegativeButton("ȡ��", null).create().show();
	};
}
